import pandas as pd
from pyecharts.charts import Pie
from pyecharts import options as opts

# 导入数据
data = pd.read_excel('第二章 图表(后15).xlsx',sheet_name='20 南丁格尔（PPT）',usecols='B:C',skiprows=1)

# 准备数据
x = data['部门'].tolist()
y = data['人数占比'].tolist()

# 创建南丁格尔玫瑰图
rose_chart = (
    Pie(init_opts=opts.InitOpts(bg_color='#00002d'))
    .add("",
         [list(z) for z in zip(x, y)],
         rosetype="area",
         )
    .set_global_opts(
        title_opts=opts.TitleOpts(
            title="2021年各部门人数分布",
            title_textstyle_opts=opts.TextStyleOpts(color="white", font_size=24),
        ),
        legend_opts=opts.LegendOpts(
            pos_top="5%",
            pos_right="5%",
            textstyle_opts=opts.TextStyleOpts(color="white")
        )
    )
    .set_series_opts(
        label_opts=opts.LabelOpts(formatter="{b}: {c} ({d}%)"),
    )
    .set_colors(
        ['rgb({r},0,{b})'.format(r=255-20*(len(y)-x+1), b=255-15*x) for x in range(len(y))]
    )
)

# 渲染图表
rose_chart.render("D:/python charm/01/可视化/第二章/图片/南丁格尔不等半径圆饼图.html")